package com.teacher.pc.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.login.LoginDto;
import com.teacher.pojo.dto.student.StudentAddDto;
import com.teacher.pojo.dto.student.StudentGetDto;
import com.teacher.pojo.dto.student.StudentUpdateDto;
import com.teacher.pojo.entity.PerStudent;
import com.teacher.pojo.entity.PerTeacher;
import com.teacher.pojo.vo.student.StudentGetVo;
import com.teacher.service.IPerStudentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ConcurrentMap;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-06-15
 */
@RestController
@RequestMapping("/pc/per-student")
public class PerStudentController {

    @Autowired
    private IPerStudentService iPerStudentService;

    /**
     * 添加入党积极分子
     *
     * @param dto
     * @return
     */
    @ApiOperation("添加学生")
    @PostMapping
    public CommonResult<String> add(@RequestBody StudentAddDto dto) {
        return iPerStudentService.add(dto);
    }

    /**
     * 删除学生
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除学生")
    public CommonResult<String> del(@RequestBody List<Long> ids) {
        iPerStudentService.removeByIds(ids);
        return CommonResult.success("删除成功");
    }

    /**
     * 更新学生信息
     *
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("更新学生信息")
    public CommonResult<String> update(@RequestBody StudentUpdateDto dto) {
        PerStudent perStudent = new PerStudent();
        BeanUtils.copyProperties(dto, perStudent);
        if (iPerStudentService.updateById(perStudent)) {
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");
    }

    /**
     * 查询学生信息
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("查询学生信息")
    public CommonResult<IPage<StudentGetVo>> get(StudentGetDto dto) {
        return iPerStudentService.getPage(dto);
    }

    /**
     * 远程搜索学生-带权限
     *
     * @param name
     * @return
     */
    @GetMapping("/byName")
    @ApiOperation("远程搜索学生-带权限")
    public CommonResult<List<PerStudent>> getByName(String name) {
        return iPerStudentService.getByName(name);
    }

    /**
     * 登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public CommonResult<ConcurrentMap<String,Object>> login(@RequestBody LoginDto dto) {
        return iPerStudentService.login(dto);
    }
}

